Skip to content

feat: Use Lock/Unlock signal from org.freedesktop.login1.Session for session lock#83

Open
calsys456 wants to merge 1 commit intolinuxdeepin:masterfrom
calsys456:master
Open

feat: Use Lock/Unlock signal from org.freedesktop.login1.Session for session lock#83
calsys456 wants to merge 1 commit intolinuxdeepin:masterfrom
calsys456:master

Conversation

@calsys456
Copy link
Contributor

@calsys456 calsys456 commented Feb 5, 2026

This is more portable and robustic.

Refined the logging system to make them more informative as well.

Summary by Sourcery

Integrate session lock and unlock handling with logind and clean up obsolete login success signaling while improving daemon logging clarity.

New Features:

  • Add support for handling session lock requests from the greeter and forwarding them to systemd-logind via D-Bus.

Enhancements:

  • Route session unlock through systemd-logind for existing sessions and adjust VT switching accordingly.
  • Remove now-unnecessary LoginSucceeded daemon/greeter messaging and related Treeland-specific activation paths.
  • Improve informational and warning logging around login, logout, session type handling, and user identification flows.
  • Clarify log messages related to starting Treeland and X11 user sessions.

…session lock

This is more portable and robustic.

Refined the logging system to make them more informative as well.
@deepin-ci-robot
Copy link

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: calsys456

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@deepin-ci-robot
Copy link

Hi @calsys456. Thanks for your PR.

I'm waiting for a linuxdeepin member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

Details

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@sourcery-ai
Copy link

sourcery-ai bot commented Feb 5, 2026

Reviewer's Guide

Implements session lock/unlock via org.freedesktop.login1 instead of custom LoginSucceeded signaling and refines daemon logging for login, session management, and greeter communication.

Sequence diagram for session lock via org.freedesktop.login1

sequenceDiagram
    actor Greeter
    participant SocketServer
    participant Display
    participant Login1Manager as OrgFreedesktopLogin1ManagerInterface

    Greeter->>SocketServer: send GreeterMessages::Lock(id)
    SocketServer->>SocketServer: read id from socket
    SocketServer->>SocketServer: qDebug Message received from greeter: Lock
    SocketServer->>Display: emit lock(socket, id)

    Display->>Display: qDebug Lock requested for session id
    Display->>Login1Manager: create with Logind::serviceName, Logind::managerPath, system bus
    Display->>Login1Manager: LockSession(QString::number(id))
Loading

Sequence diagram for session unlock via org.freedesktop.login1

sequenceDiagram
    actor Greeter
    participant SocketServer
    participant Display
    participant Login1Manager as OrgFreedesktopLogin1ManagerInterface
    participant VirtualTerminal

    Greeter->>SocketServer: send GreeterMessages::Unlock(user, password)
    SocketServer->>SocketServer: read user, password from socket
    SocketServer->>Display: emit unlock(socket, user, password)

    alt user is dde
        Display->>Display: check user == dde
        Display-->>SocketServer: emit loginFailed(socket, user)
    else normal user
        Display->>Display: qInfo Start identify user
        Display->>Display: find Auth in auths with auth->user == user and auth->xdgSessionId > 0
        alt matching Auth found
            Display->>Login1Manager: create with Logind::serviceName, Logind::managerPath, system bus
            Display->>Login1Manager: UnlockSession(QString::number(auth->xdgSessionId))
            Display->>VirtualTerminal: jumpToVt(auth->tty, false)
            Display->>Display: qInfo Successfully identified user
        else no matching Auth
            Display->>Display: qWarning No active session found for user
            Display-->>SocketServer: emit loginFailed(socket, user)
        end
    end
Loading

Updated class diagram for Display, SocketServer and TreelandDisplayServer

classDiagram
    class Display {
        +connected(socket: QLocalSocket*)
        +login(socket: QLocalSocket*, user: QString, password: QString, session: Session)
        +logout(socket: QLocalSocket*, id: int)
        +lock(socket: QLocalSocket*, id: int)
        +unlock(socket: QLocalSocket*, user: QString, password: QString)
        <<signal>> loginFailed(socket: QLocalSocket*, user: QString)
        -auths: QList~Auth*~
        -m_socketServer: SocketServer*
    }

    class SocketServer {
        +informationMessage(socket: QLocalSocket*, message: QString)
        +loginFailed(socket: QLocalSocket*, user: QString)
        <<signal>> login(socket: QLocalSocket*, user: QString, password: QString, session: Session)
        <<signal>> logout(socket: QLocalSocket*, id: int)
        <<signal>> lock(socket: QLocalSocket*, id: int)
        <<signal>> unlock(socket: QLocalSocket*, user: QString, password: QString)
        <<signal>> connected(socket: QLocalSocket*)
    }

    class TreelandDisplayServer {
        +start(socketServer: SocketServer*)
        +stop()
        +activateUser(user: QString, xdgSessionId: int)
        +onLoginFailed(user: QString)
        -m_socketServer: SocketServer*
        -m_greeterSockets: QList~QLocalSocket*~
    }

    class GreeterMessages {
        <<enum>>
        +Lock
        +Unlock
        +Logout
        +Suspend
        +Hibernate
        +HybridSleep
        +BackToNormal
    }

    class DaemonMessages {
        <<enum>>
        +HostName
        +Capabilities
        +LoginFailed
        +InformationMessage
        +UserActivateMessage
    }

    class OrgFreedesktopLogin1ManagerInterface {
        +LockSession(id: QString)
        +UnlockSession(id: QString)
    }

    Display --> SocketServer : uses
    TreelandDisplayServer --> SocketServer : uses
    Display --> OrgFreedesktopLogin1ManagerInterface : locks_unlocks_sessions
    SocketServer --> GreeterMessages : parses
    SocketServer --> DaemonMessages : sends
Loading

File-Level Changes

Change Details Files
Wire greeter lock/unlock requests to logind LockSession/UnlockSession and VT switching via Display/SocketServer.
  • Connect SocketServer::lock signal to Display::lock alongside existing logout/unlock connections
  • Add GreeterMessages::Lock handling in SocketServer::handleMessage, reading session id and emitting lock(socket, id)
  • Implement Display::lock to call org.freedesktop.login1 Manager.LockSession for the given session id with debug logging
  • Change Display::unlock to use org.freedesktop.login1 Manager.UnlockSession with the stored xdgSessionId, then jump to VT, and improve logging for success and failure paths
src/daemon/Display.cpp
src/daemon/Display.h
src/daemon/SocketServer.cpp
src/daemon/SocketServer.h
src/common/Messages.h
Remove custom LoginSucceeded signaling path and Treeland-specific activation on login success.
  • Remove Display::loginSucceeded signal and its connection to SocketServer::loginSucceeded
  • Delete SocketServer::loginSucceeded slot and associated DaemonMessages::LoginSucceeded enum value
  • Remove TreelandDisplayServer::onLoginSucceeded and declaration, and the loginSucceeded broadcast to greeters
  • Drop Treeland-only loginSucceeded emission and activateSession call from Display::login once auth is created
src/daemon/Display.cpp
src/daemon/Display.h
src/daemon/SocketServer.cpp
src/daemon/SocketServer.h
src/common/Messages.h
src/daemon/TreelandDisplayServer.cpp
src/daemon/TreelandDisplayServer.h
Improve logging levels and messages for authentication, session switching, and logout.
  • Add qWarning() and qInfo() logs around login attempts, authentication success, and final login success, including username and session details
  • Change some qDebug() messages to qInfo() for user identification and session selection
  • Add explicit logs when stopping Treeland, starting X11, and when logout is requested for a session id
  • Adjust UserSession Treeland startup log message to clearly indicate Treeland sessions instead of generic Wayland
src/daemon/Display.cpp
src/daemon/UserSession.cpp

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - I've found 1 issue, and left some high level feedback:

  • The new lock/unlock paths call login1 LockSession/UnlockSession synchronously without checking for DBus errors or unavailable logind; consider using QDBusPendingReply or checking the return value and logging/handling failures to avoid silently ignoring issues.
  • Logging has been made more verbose but is a mix of qDebug, qInfo, and qWarning for similar events (e.g., logout vs. lock vs. login); it may be worth standardizing the log levels and including consistent identifiers (session id, user, tty) to make traces easier to follow.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- The new lock/unlock paths call login1 `LockSession`/`UnlockSession` synchronously without checking for DBus errors or unavailable logind; consider using `QDBusPendingReply` or checking the return value and logging/handling failures to avoid silently ignoring issues.
- Logging has been made more verbose but is a mix of `qDebug`, `qInfo`, and `qWarning` for similar events (e.g., logout vs. lock vs. login); it may be worth standardizing the log levels and including consistent identifiers (session id, user, tty) to make traces easier to follow.

## Individual Comments

### Comment 1
<location> `src/daemon/Display.cpp:307-310` </location>
<code_context>
         } else if (session.xdgSessionType() == QLatin1String("x11")) {
             auth->type = X11;

+            qInfo() << "Stopping Treeland";
             daemonApp->treelandConnector()->disconnect();
             m_treeland->stop();
             QThread::msleep(500); // give some time to treeland to stop properly

             // Start X server
</code_context>

<issue_to_address>
**suggestion:** Consider extracting the Treeland shutdown sequence into a helper to avoid duplication.

The `disconnect()`, `m_treeland->stop()`, and `QThread::msleep(500)` pattern is duplicated in both the X11 and non-X11 paths (now with an added log line). Centralizing this sequence in a small helper like `stopTreeland()` would make future changes (e.g., timeout or additional cleanup) safer and keep the behavior aligned across branches.

Suggested implementation:

```cpp
            auth->type = X11;

            stopTreeland();

            // Start X server

```

```cpp
        } else {
            auth->type = Wayland;

            stopTreeland();

```

To fully implement the refactoring, you should also:

1. **Implement the helper in `src/daemon/Display.cpp`**, as a `Display` member function, somewhere near other small helpers:

```cpp
void Display::stopTreeland()
{
    qInfo() << "Stopping Treeland";
    daemonApp->treelandConnector()->disconnect();

    if (m_treeland) {
        m_treeland->stop();
    }

    // Give some time to Treeland to stop properly
    QThread::msleep(500);
}
```

2. **Declare the helper in `src/daemon/Display.h`** in the `Display` class, preferably in the `private:` section:

```cpp
private:
    void stopTreeland();
    // ... existing members
```

3. If `QThread` is not already included in `Display.cpp`, ensure the correct include exists at the top of the file:

```cpp
#include <QThread>
```

These changes will centralize the Treeland shutdown sequence, keep the logging consistent, and make future adjustments (e.g., changing the timeout or adding extra cleanup) safer and easier.
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@calsys456
Copy link
Contributor Author

Paired with linuxdeepin/treeland#735

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants